const mongoose = require('mongoose')

const Schema = mongoose.Schema

mongoose.connect('mongodb://localhost/vue-blog')

const userSchema = new Schema({
  username: {
    type: String,
    required: true
  },
  email: {
    type: String,
    required: true
  },
  password: {
    type: String,
    required: true
  },
  // 超级管理员 admin
  // 普通用户 normal
  role: {
    type: String,
    required: true,
    default: 'normal'
  },
  avatar: {
    type: String,
    default: 'https://www.ipicbed.com/images/2021/12/23/avater01.th.jpg'
  },
  created_time: {
    type: Date,
    default: Date.now
  },
  last_modified_time: {
    type: Date,
    default: Date.now
  },
  introduce: {
    type: String,
    default: '这个人什么都没有说~~~'
  },
  // 朋友圈
  friends_circle: {
    "attention_list": [
      {
        "username": String,
        "user_id": String,
        "avatar": String,
        "tips_type": {
          type: String,
          default: '关注'
        },
        "request_time": String,
      }
    ],
    "be_focused_list": [
      {
        "username": String,
        "user_id": String,
        "avatar": String,
        "tips_type": {
          type: String,
          default: '关注'
        },
        "request_time": String,
      }
    ],
    "friends_list": [
      {
        "username": String,
        "user_id": String
      }
    ],
    // 被请求的对象列表
    "requested_list": [
      {
        "username": String,
        "user_id": String,
        "avatar": String,
        "tips_type": {
          type: String,
          default: '好友请求'
        },
        "request_time": String,
        "content": {
          type: String,
          default: '加个好友，一起交流下~'
        }
      }
    ],
    // 请求的对象列表
    "request_list": [
      {
        "username": String,
        "user_id": String,
        "avatar": String,
        "tips_type": {
          type: String,
          default: '好友请求'
        },
        "request_time": String,
        "content": {
          type: String,
          default: '加个好友，一起交流下~'
        }
      }
    ],
  },
  // 收藏以及点赞
  user_article: {
    collect: [
      {
        article_id: String,
        article_title: String,
        article_info: String
      },
    ],
    like: [
      {
        article_id: String,
        article_title: String,
        article_info: String
      }
    ]
    // articleNum: {
    //   type: String,
    //   default:'0'
    // }
  },
  articleNum: {
    type: String,
    default: '0'
  },
  login_time: {
    type: Date
  },
  logout_time: {
    type: Date
  }
})

// const User = mongoose.model('User',userSchema)

// User.create({
//   username: 'feng',
//   email: 'abc@163.com',
//   password: '123',
//   role:'admin'
// }).then((res) => {
//   console.log('用户创建成功');
// }).catch((err) => {
//   console.log('用户创建失败');
// });

module.exports = mongoose.model('User', userSchema)